#include<iostream>
#include<thread>
using namespace std;

class A {
public:
    mutable int num;
    void thread_work(int num) {
        num = 199;//修改不会影响main的值
        cout << "子线程num=" << num << endl;
        cout << "子线程thread_work执行了, " << "threadid=" << std::this_thread::get_id() << endl;
    }
};

int main() {
    cout << "主线程id是" << std::this_thread::get_id() << endl;
    A a;
    int num = 100;
    //第一个参数是对象函数指针，第二个参数对象，其后参数为函数所需参数
    thread th(&A::thread_work, a,num);
    th.join();
    cout << "主线程的num=" << num << endl;
    cout << "主线程的a.num=" << a.num << endl;
    cout << "主线程执行完毕" << endl;
    return 0;
}
/* ————————————————
版权声明：本文为CSDN博主「LeetCode刷题记录」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
原文链接：https://blog.csdn.net/qq_42147969/article/details/118325905 */